package com.example.rentalcar.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;
import com.example.rentalcar.entity.Users;

import java.util.List;

@Mapper
public interface UsersMapper extends BaseMapper<Users> {

    @Select("SELECT * FROM users WHERE user_name=#{userName} AND user_password=#{userPassword}")
    Users findByUsernameAndPassword(@Param("userName") String userName, @Param("userPassword") String userPassword);

    @Select("SELECT * FROM users WHERE user_id = #{userId}")
    Users findById(Long userId);

    @Select("SELECT * FROM users LIMIT #{start}, #{limit}")
    List<Users> findAll(@Param("start") int start, @Param("limit") int limit);

    @Select("SELECT * FROM users WHERE user_name=#{userName}")
    Users findByUsername(String userName);

    @Select("SELECT * FROM users WHERE user_phone=#{userPhone}")
    Users findByUserPhone(String userPhone);

    @Insert("INSERT INTO users (user_name, user_phone, user_sex, user_password, user_idcard1, user_driveCard1, user_stu, user_idcard2, user_driveCard2) " +
            "VALUES (#{userName}, #{userPhone}, #{userSex}, #{userPassword}, #{userIdcard1}, #{userDriveCard1}, #{userStu}, #{userIdcard2}, #{userDriveCard2})")
    void save(Users user);

    @Update("UPDATE users SET user_name = #{userName}, user_phone = #{userPhone}, user_sex = #{userSex}, " +
            "user_password = #{userPassword}, user_idcard1 = #{userIdcard1}, user_driveCard1 = #{userDriveCard1}, " +
            "user_stu = #{userStu}, user_idcard2 = #{userIdcard2}, user_driveCard2 = #{userDriveCard2} WHERE user_id = #{userId}")
    void update(Users user);

    @Delete("DELETE FROM users WHERE user_id = #{userId}")
    void deleteById(Long userId);
}
